package com.example.smartgreenhouse.service.impl;
import com.example.smartgreenhouse.entity.LightHistoryStatus;
import com.example.smartgreenhouse.mapper.LightStatusMapper;
import com.example.smartgreenhouse.service.LightStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class LightStatusServiceImpl implements LightStatusService {
    private final LightStatusMapper lightStatusMapper;

    @Override
    @Transactional
    public void insertLightStatus(Long lightId, Integer isOn, Boolean isAuto, Long greenhouseId) {
        LightHistoryStatus status = new LightHistoryStatus();
        status.setIsOn(isOn);
        status.setIsAuto(isAuto);
        status.setGreenhouseId(greenhouseId);
        if (lightId != null) {
            status.setLightId(lightId);
        }
        lightStatusMapper.insert(status);
    }
}